﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using Microsoft.Reporting.WebForms;
using System.Net;
using System.Security.Principal;
namespace Crosland.Automotriz.Web.Repuestos
{
    public partial class wFrmProcesoArticulosABCReporte : System.Web.UI.Page
    {
        string idNegocio = ConfigurationManager.AppSettings["Negocio"];
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                mostrarReport();
                lblNumProceso.Text = Session["NUM_PROC"].ToString();

            }
        }

        void mostrarReport()
        {

            try
            {
                int num_proc = Convert.ToInt32(Session["NUM_PROC"].ToString());

                ReportViewer1.ServerReport.ReportServerCredentials = new MyReportServerCredentials();
                ReportViewer1.ProcessingMode = ProcessingMode.Remote;
                ReportViewer1.ServerReport.ReportServerUrl = new Uri(ConfigurationManager.AppSettings["RsServer"]);
                ReportViewer1.ServerReport.ReportPath = "/RepuestosMay/rs_REP_ProcesoABC";


                ReportParameter[] parametro = new ReportParameter[1];
                parametro[0] = new ReportParameter();
                parametro[0].Name = "num_proc";
                parametro[0].Values.Add(Convert.ToString(num_proc));
                parametro[0].Visible = false;

                ReportViewer1.ServerReport.SetParameters(parametro);
                ReportViewer1.ServerReport.Refresh();

            }
            catch (Exception ex)
            {
             


            }




        }



        [Serializable]
        public sealed class MyReportServerCredentials : IReportServerCredentials
        {
            public WindowsIdentity ImpersonationUser
            {
                get
                {

                    return null;
                }
            }

            public ICredentials NetworkCredentials
            {
                get
                {


                    // User name
                    string userName = ConfigurationManager.AppSettings["RSUser"];

                    if (string.IsNullOrEmpty(userName))
                        throw new Exception(
                            "Missing user name from web.config file");

                    // Password
                    string password =
                        ConfigurationManager.AppSettings["RSPassword"];

                    if (string.IsNullOrEmpty(password))
                        throw new Exception(
                            "Missing password from web.config file");

                    // Domain
                    string domain =
                        ConfigurationManager.AppSettings["RSDomain"];

                    if (string.IsNullOrEmpty(domain))
                        throw new Exception(
                            "Missing domain from web.config file");

                    return new NetworkCredential(userName, password, domain);
                }
            }

            public bool GetFormsCredentials(out Cookie authCookie,
                        out string userName, out string password,
                        out string authority)
            {
                authCookie = null;
                userName = null;
                password = null;
                authority = null;


                return false;
            }


        }

        protected void btnAtras_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Repuestos/wFrmProcesarArticulosABC.aspx?id=" + idNegocio);
        }

    }
}